package models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Classe {

	private static Connection conexao;
	private static Statement comando;
	
	
	
	/***********************************************************************************/
	
	protected static void conectar() throws SQLException {  
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
		}

			conexao = DriverManager.getConnection(  
			        "jdbc:postgresql://localhost:5432/SGRv2",  
			        "postgres",  
			        "senha");
		
			comando =  conexao.createStatement();
	}

	/***********************************************************************************/
	
	
		  int id;
	      String nome;
	      String caracteristica;
	      
	      	public int getid() {
				return id;
			}
			public void setid(int id) {
				this.id = id;
			}
			

			public String getnome() {
				return nome;
			}
			public void setnome(String nome ) {
				this.nome = nome ;
			}			

			public String getcaracteristica() {
				return caracteristica;
			}
			public void setcaracteristica(String caracteristica ) {
				this.caracteristica = caracteristica ;
			}
			
			
			/*********************************************************************************/
			
			public static List<Classe> Classes() throws SQLException
			{
				conectar();
		    	
		    	ResultSet reader = comando.executeQuery("select * from classe");
		    	  
		    	
				List<Classe> classes = new ArrayList<Classe>();
				
				 while (reader.next())
			        {   			 
					 Classe novo = new Classe();
					 
			            try
			            {
			                novo.setid(((int)reader.getInt("id") ));
			            }
			            catch (Exception e) {
						}
			            try
			            {
			                novo.setnome((String)reader.getString("nome"));
			            }
			            catch (Exception e) {
						}
			            
			            try
			            {
			                novo.setcaracteristica((String)reader.getString("caracteristica"));
			            }
			            catch (Exception e) {
						}
			            
			            classes.add(novo);
			        }
				
				return classes;
			}
			
			/*********************************************************************************/
					
			
}
